<?php

/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 */

if('ROOT_PATH'==ROOT_PATH){
	
}

require_once ROOT_PATH . '/lib/confs/sysConf.php';
require_once ROOT_PATH . '/lib/exception/ExceptionHandler.php';
require_once ROOT_PATH . '/lib/common/FormCreator.php';
require_once ROOT_PATH . '/lib/common/authorize.php';
require_once ROOT_PATH . '/lib/common/TemplateMerger.php';
require_once ROOT_PATH . '/lib/common/AjaxCalls.php';

require_once ROOT_PATH . '/lib/models/maintenance/UserGroups.php';
require_once ROOT_PATH . '/lib/models/maintenance/Users.php';
require_once ROOT_PATH . '/lib/models/maintenance/Rights.php';

require_once ROOT_PATH . '/lib/models/surveys/Answers.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/surveys/Options.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/surveys/Questions.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/surveys/Surveys.php';//Chinh Nguyen add


require_once ROOT_PATH . '/lib/models/skillmatrix/SkillGroup.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillExpertise.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillUser.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillIndividual.php';
require_once ROOT_PATH . '/lib/models/skillmatrix/export/SkillMatrixCSVExport.php';
require_once ROOT_PATH . '/lib/models/hrfunct/EmpLang.php';
require_once ROOT_PATH . '/lib/models/eimadmin/LanguageInfo.php';

require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
require_once ROOT_PATH . '/FirePHPCore/FirePHP.class.php';

date_default_timezone_set('Europe/London');

/** PHPExcel */
require_once ROOT_PATH . '/lib/Classes/PHPExcel.php';
require_once ROOT_PATH . '/lib/Classes/PHPExcel/Worksheet/PageSetup.php';

require_once ROOT_PATH . '/lib/models/surveys/mail/MailSurvey.php';//Chinh Nguyen add


require_once ROOT_PATH . '/lib/extractor/skillmatrix/EXTRACTOR_skillMatrix.php';


/**
 * Controller for skill matrix module
 */
class SkillMatrixController {

	private $authorizeObj;

    /**
     * Constructor
     */
    public function __construct() {
        if (isset($_SESSION) && isset($_SESSION['fname']) ) {
			$this->authorizeObj = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
        }
    }

    /**
     * Handle incoming requests
     * @param String code Recruit code
     */
    public function handleRequest($code) {
		
		if (empty($code) ) {
			trigger_error("Invalid Action " . $_GET['action'], E_USER_NOTICE);
			return;
		}	
		
		switch ($code) {
			
			case 'SkillMatrix' :
				
				$viewExtractor = new EXTRACTOR_SkillMatrix();
				if(isset($_GET['id']))
					$id = $_GET['id'];
				else 
					$id = null;
					
				$userID = $_SESSION['empID'];
			
	            switch ($_GET['action']) {	            	
	            	case 'Summary':
	            		$this->_viewTechnicalSummary();	            		
	            		break;
	            	case 'Individual':
	            		$this->_viewSummary();
	            		break;	
	            	case 'ListGroup':
	            		$this->_viewGoupSkills();
	            		break;
	            	case 'AddGroup':
	            		$this->_viewAddSkillGroup($id =null);
	            		break;
	            	case 'SaveGroup':
	            		$skillGroup = $viewExtractor->parseAddSkillGroup($_POST);
	            		$this->_saveSkillGroup($skillGroup);
	            		break;	            	
	            	case 'EditGroup':
	            		$skillGroup = $viewExtractor->parseUpdateSkillGroup($_POST);
	            		$this->_saveSkillGroup($skillGroup);
	            		break;
	            	case 'DeleteSkillGroup':
	            		$this->_deleteSkillGroup($id);
	            		break;		            			            		
	            	case 'ShowEditSkillGroup':
	            		$this->_viewEditSkillGroup($id);	            		
	            		break;
	            	case 'AddSkillExpertise':
	            		$skillExpertise = $viewExtractor->parseAddSkillExpertise($_POST);
	            		$this->_saveSkillExpertise($skillExpertise);
	            		break;
	            	case 'DeleteSkillExpertise' :
	                	$ids = $_POST['chkID'];
	                    $this->_deleteSkillExpertise($ids);
	                    break;	
	            	case 'Define':
	            		$this->_viewDefine();
	            		break;	
	            	case 'saveDeclare':
	            		$array= $viewExtractor->parseAddSkillUsers($_POST,$userID);
	            		$this->_saveSkillUsers($array);
	            		break;	
	            	case 'Export':
	            		$this->_export();
	            	    break;
	            	case 'ExportTechnical':
	            		$this->_exportTechnical();
	            		break;           		
	            	case 'Declare':	            			                	
	                	$this->_viewDeclare();	                  
	            		break;
	            	case 'UpdateOrder':	            		
	            		$this->_saveGroupsOrder();
	            		break;	 
	            	               
	            }
                break;

	    }
    }
    
    private function _saveGroupsOrder(){
    	$groups = SkillGroup::getAll();
    	foreach ($groups as $group){
    		$id = $group->getId();    		    
    		if(isset($_POST["order$id"]) ){
    			$order = (int)$_POST["order$id"];
    			if($order == $_POST["order$id"]){
    				$group->setSkillGroupOrder($order);
    				$group->save();
    			}
    		}
    		$skillexpertises = SkillGroup::getSkillExpertise($id);
    		foreach ($skillexpertises as $skillexpertise){
    			$exid = $skillexpertise->getId();
    			if(isset($_POST['order'.$id.'exp'.$exid]) ){
    				$exOrder = $_POST['order'.$id.'exp'.$exid]; 
    				if($exOrder == $_POST['order'.$id.'exp'.$exid]){
    					$skillexpertise->setSkillExpertiseOrder($exOrder);
    					$skillexpertise->save();
    				}
    			}
    		}
    	}
    	$message ="Update order successfull";
    	$this->redirect($message);
    	
    }	
    private function _viewDeclare(){
    	$userID = $_SESSION['empID'];
    	$skillIndividual = SkillIndividual::getSkillIndividualByUser($userID);  
    	$arr = array();
    	if(isset($_POST['expertise']))
    	{
    		$expertise = $_POST['expertise'];    	
			$arr['expertise']=$expertise;
    		if($expertise=='2'){
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType(2);    			
    		}elseif($expertise=='1'){
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType(1);    			
    		}else{
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType();
    		}    		
    	}else{    	  		
    		if($skillIndividual->getSkillIndividualExpertise()=='2'){
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType(2);
    		}elseif($skillIndividual->getSkillIndividualExpertise()=='1'){
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType(1);
    		}else{
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType();
    		}    
    	}
    	
    	$arr['skillMatrix']= $skillMatrix;
    	
    	$arr['skillIndividual']=$skillIndividual;
		$path = "/templates/skillmatrix/declare.php";
		$template = new TemplateMerger($arr, $path);
		$template->display();
    }
    
    
	private function _viewGoupSkills(){
    	$skillMatrix = SkillGroup::getAll(); 
		//$this->_authenticateViewLeaveDetails();
		$path = "/templates/skillmatrix/groupskills.php";
		$template = new TemplateMerger($skillMatrix, $path);
		$template->display();
    }
    
  private function _viewSummary(){
    	if(isset($_POST['grouptype']) && $_POST['grouptype']!=''){    		
    		if(isset($_POST['skillgroup']) && $_POST['skillgroup']!='' ){    			
    			$skillMatrixByGroup = SkillGroup::getSkillMatrixByGroup($_POST['skillgroup']);
    			if(in_array($_POST['grouptype'],explode(",",$skillMatrixByGroup[0][4]))){
	    			$skillMatrix = $skillMatrixByGroup;	    			
    			}else{
    				//$skillgroup = new SkillGroup();
    				$skillMatrix= array();
    			}
    			$records['skillgroup'] = $_POST['skillgroup'];	
	    		$records['expertise'] = $skillMatrixByGroup[0][4];
	    		$records['grouptype'] = $_POST['grouptype'];	    		
    		}else{
    			$skillMatrix = SkillGroup::getSkillMatrixByGroupType($_POST['grouptype']);
    			$records['expertise'] = $_POST['grouptype'];
    			$records['skillgroup'] = '';
    			$records['grouptype'] = $_POST['grouptype'];
    		}    			
    	}elseif(isset($_POST['skillgroup']) && $_POST['skillgroup']!=''){
    		$skillMatrix = SkillGroup::getSkillMatrixByGroup($_POST['skillgroup']);    		
    		$records['expertise'] = $skillMatrix[0][4];
    		$records['skillgroup'] = $_POST['skillgroup'];
    		$records['grouptype'] = '';	
    	}else{
    		$skillMatrix = SkillGroup::getSkillMatrixByGroup();
    		$records['skillgroup'] = null;
    		$records['grouptype'] = '';	
    		$records['expertise'] = null;
    	}
    	if(isset($_POST['lastupdate']))
    		$records['lastupdate']=1;
    	else
    		$records['lastupdate']=0;    	
    	$records['skillmatrix']=$skillMatrix;
		//$this->_authenticateViewLeaveDetails();
		$path = "/templates/skillmatrix/summary.php";
		$template = new TemplateMerger($records, $path);
		$template->display();
    }

    private function _viewTechnicalSummary(){
    	$records= array();
		//$this->_authenticateViewLeaveDetails();
		$path = "/templates/skillmatrix/technicalSummary.php";
		$template = new TemplateMerger($records, $path);
		$template->display();
    }
    
    
	private function _viewAddSkillGroup($id=null) {
		if ($this->authorizeObj->isAdmin()) {
	    	$this->_editSkillGroup($id);
	    } else {
            $this->_notAuthorized();
		}
	}
	
	
	
	private function _viewEditSkillGroup($id){
		if ($this->authorizeObj->isAdmin()) {
			$path = '/templates/skillmatrix/editSkillGroup.php';
			try {			
				if (empty($id)) {
					$skillGroup = new SkillGroup();				
				} else {
					$skillGroup = SkillGroup::getSkillGroup($id);				
				}
				
				$objs['skill_group_id'] = $id;
				$objs['skill_group_name']= $skillGroup->getSkillGroupName();
				$objs['skill_group_type']= $skillGroup->getSkillGroupType();
				$objs['skill_group_order']= $skillGroup->getSkillGroupOrder();
				
				
				
				$template = new TemplateMerger($objs, $path);
				$template->display();
			} catch (NewsException $e) {
				$message = 'Operation Failed';
	            $this->redirect($message);
			}
		} else {
            $this->_notAuthorized();
		}
	}
	
	private function _saveSkillGroup($skillGroup){
		if ($this->authorizeObj->isAdmin()) {
			try {
				
				$groupID=$skillGroup->save();
	        	$message = 'Successfully Added';
				$maxId =SkillGroup::getMaxId();		
				$maxId = $groupID?$groupID:$maxId;
        		$URL = "CentralController.php?skillMatrixcode=SkillMatrix&action=ShowEditSkillGroup&id=$maxId";
	        	$this->redirect($message,$URL);
			} catch (SkillGroupException $e) {
				$message = 'Failed to Add';
	        	$this->redirect($message);
			}
		} else {
            $this->_notAuthorized();
		}
		
	}
	
	private function _deleteSkillGroup($id) {
			if ($this->authorizeObj->isAdmin()) {
				try {					
	        		$count = SkillGroup::delete($id);
	        		$message = 'Successfully Deleted';
				} catch (newsException $e) {
					$message = 'Failed to Delete';
				}
				$URL = "CentralController.php?skillMatrixcode=SkillMatrix&action=ListGroup";
	        	$this->redirect($message,$URL);
	            //$this->_viewGoupSkills();
			} else {
	            $this->_notAuthorized();
			}
	    }
	
	private function _saveSkillExpertise($skillExpertise){
		if ($this->authorizeObj->isAdmin()) {
			try {
				
				$expertiseID=$skillExpertise->save();
	        	$message = 'Successfully Added';
				$groupID = $skillExpertise->getSkillGroupID();
        		$URL = "CentralController.php?skillMatrixcode=SkillMatrix&action=ShowEditSkillGroup&id=$groupID";
	        	$this->redirect($message,$URL);
			} catch (SkillGroupException $e) {
				$message = 'Failed to Add';
	        	$this->redirect($message);
			}
		} else {
            $this->_notAuthorized();
		}
		
	}
	
	private function _saveSkillUsers($array){
			$skillUsers = $array['skillUsers'];
			$skillIndividual = $array['skillindividual'];
			try {
				if(count($skillUsers)>0){
					foreach ($skillUsers as $skillUser){
						$skillUser->save();
						
					}
				}
				
				$skillIndividual->save();
				//$expertiseID=$skillExpertise->save();
	        	$message = 'Successfully Added';
				//$groupID = $skillExpertise->getSkillGroupID();
        		$URL = "CentralController.php?skillMatrixcode=SkillMatrix&action=Declare";
	        	$this->redirect($message,$URL);
			} catch (SkillGroupException $e) {
				$message = 'Failed to Add';
	        	$this->redirect($message);
			}
	}
	
	private function _editSkillGroup($id = null) {
		$path = '/templates/skillmatrix/addSkillGroup.php';
		try {			
			if (empty($id)) {
				$skillGroup = new SkillGroup();				
			} else {
				$skillGroup = SkillGroup::getSkillGroup($id);				
			}
			
			$objs['skill_group_id'] = $id;
			$objs['skill_group_name']= $skillGroup->getSkillGroupName();
			$objs['skill_group_type']= $skillGroup->getSkillGrouptype();
			$objs['skill_group_order']= $skillGroup->getSkillGroupOrder();
			
			
			$template = new TemplateMerger($objs, $path);
			$template->display();
		} catch (NewsException $e) {
			$message = 'Operation Failed';
            $this->redirect($message);
		}
    }
    
    
		private function _deleteSkillExpertise($ids) {
			if ($this->authorizeObj->isAdmin()) {
				try {
					$skillExpertiseID = $ids[0];
					$skillExpertise = SkillExpertise::getSkillExpertise($skillExpertiseID);					
					$groupID = $skillExpertise->getSkillGroupID();
					$count = SkillExpertise::delete($ids);
        			$message = 'Successfully Deleted';
        			$URL = "CentralController.php?skillMatrixcode=SkillMatrix&action=ShowEditSkillGroup&id=$groupID";
		        	//die($surveyid);
		        	$this->redirect($message,$URL);
	        		
					} catch (newsException $e) {
						$message = 'Failed to Delete';
						$this->redirect($message);
					}
		           // echo "<script> window.history.go(-1); </script>\n";
					//exit ();
				} else {
		            $this->_notAuthorized();
				}
		 }
		 
		private function _exportTechnical(){
		 	
		 	
		 	date_default_timezone_set('Europe/London');

			require_once '../Classes/PHPExcel.php';
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			// Set properties
			$objPHPExcel->getProperties()->setCreator("Skill Matrix module")
										 ->setLastModifiedBy("Chinh Nguyen")
										 ->setTitle("Skill Matrix")
										 ->setSubject("Skill Matrix")
										 ->setDescription("Skill Matrix")
										 ->setKeywords("Skill Matrix")
										 ->setCategory("Skill Matrix");
			$objPHPExcel->setActiveSheetIndex(0);
			// Rename sheet
			$objPHPExcel->getActiveSheet()->setTitle('Staff technical Summary');
			$objPHPExcel->getActiveSheet()->freezePane('C5');
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('B1:C2');
			$objPHPExcel->getActiveSheet()->setCellValue('B1',"STAFF TECHNICAL SUMMARY");			
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->getColor()->applyFromArray( array('rgb' => 'FF0000'));
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(14);
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			
			$objPHPExcel->getActiveSheet()->mergeCells('B3:C3');
			$date = date("Y-M-d"); 
			$objPHPExcel->getActiveSheet()->setCellValue('B3',"Last update: ".$date);
			$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(3);
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
			$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
			// Add some data
			$empList = EmpInfo::getEmpSkillInfo();
			//$empList = SkillIndividual::getEmpSkillInfo($expertiseIds);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,4,"#" );
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1,4,"Employee Name" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(1,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2,4,"Position" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(2,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3,4,"# Year of experience" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(3,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4,4,"Foreign language" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(4,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5,4,"Foreign language Level" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(5,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6,4,"Work abroad" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(6,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7,4,"Expertise" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(7,4)->getFont()->setBold(true);
			$rowstart = 5;
			$colstart = 1;
			$lanlist = LanguageInfo::getLang();
			$grdcodes = array("Poor"=> 1 ,"Average"=>2 , "Good"=>3 ,"Excellent"=>4);
			$name=array_keys($grdcodes);
			$code=array_values($grdcodes);
			$count = 1;
			foreach($empList as $employee){				 
				$emplan = EmpLanguage::getAssEmpLang($employee[0]);
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart-1,$rowstart,$count);
					$count++;				
				if(!count($emplan)>0){
					
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[1]." ".$employee[4]." ".$employee[3] );
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
					//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
					$colstart++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[7]);
					$colstart++;
					
					$skillIndividual = SkillIndividual::getSkillIndividualByUser($employee[0]);
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualNumOfYear());
					$colstart++;
					$colstart++;
					//$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,null);
					$colstart++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualWorkAbroad());
					$colstart++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualExpertise());
					
					$colstart=1;
					$rowstart++;
				}else{
					for($i=0;$i<count($emplan);$i++){
						if($i==0){	
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[1]." ".$employee[4]." ".$employee[3] );
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
							//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
							$colstart++;
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[7]);
							$colstart++;
							
							$skillIndividual = SkillIndividual::getSkillIndividualByUser($employee[0]);
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualNumOfYear());
							$colstart++;
							$lname='';
							for($a=0;count($lanlist)>$a;$a++)								
								if($emplan[$i][1] == $lanlist[$a][0])
								   $lname=$lanlist[$a][1];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$lname);
							$colstart++;
							$rate='';
							
							for($b=0;count($grdcodes)>$b;$b++)
								if($emplan[$i][3] == $code[$b])
								   $rate=$name[$b];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$rate);
							$colstart++;
							
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualWorkAbroad());
							$colstart++;
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualExpertise());
							
							$colstart=1;
							$rowstart++;
						}else{
							//Merge here
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);										
							$colstart++;
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);							
							$colstart++;							
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$colstart++;
							$lname='';
							for($a=0;count($lanlist)>$a;$a++)
								if($emplan[$i][1] == $lanlist[$a][0])
								   $lname=$lanlist[$a][1];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$lname);
							$colstart++;
							$rate='';
							$name=array_keys($grdcodes);
							for($b=0;count($grdcodes)>$b;$b++)
								if($emplan[$i][3] == $code[$b])
								   $rate=$name[$b];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$rate);
							$colstart++;
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$colstart++;
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							
							$colstart=1;
							$rowstart++;
						}
					}
					
				}
			}

			
			ob_end_clean();
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="'.date('Y-m-d').'_TechnicalSumary.xls"');
			header('Cache-Control: max-age=0');
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); 
	  	} 
		 
		private function _export(){
		 	
		 	
		 	date_default_timezone_set('Europe/London');

			require_once '../Classes/PHPExcel.php';
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			// Set properties
			$objPHPExcel->getProperties()->setCreator("Skill Matrix module")
										 ->setLastModifiedBy("Chinh Nguyen")
										 ->setTitle("Skill Matrix")
										 ->setSubject("Skill Matrix")
										 ->setDescription("Skill Matrix")
										 ->setKeywords("Skill Matrix")
										 ->setCategory("Skill Matrix");
		
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setTitle('Skill Matrix');
			$objPHPExcel->getActiveSheet()->freezePane('C7');
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('B2:C3');
			$objPHPExcel->getActiveSheet()->setCellValue('B2',"S3 Skill Matrix");
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => 'FF0000'));
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setSize(14);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			// Add some data
			$empList = EmpInfo::getEmpSkillInfo();
			$rowstart = 5;
			$colstart = 1;
			//$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setAutoSize(true);
		
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart-1,$rowstart,"#");
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart-1,$rowstart,$colstart-1,$rowstart+1);			
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart-1,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart-1,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(3);	
			
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Employee");
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart,$colstart,$rowstart+1);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);			
			$colstart++ ;
			if(isset($_POST['grouptype']) && $_POST['grouptype']!=''){    		
    			if(isset($_POST['skillgroup']) && $_POST['skillgroup']!='' ){    			
    				$skillgroup = SkillGroup::getSkillGroup($_POST['skillgroup']);
    				if(in_array($_POST['grouptype'],explode(",",$skillgroup->getSkillGroupType()))){
	    			//if($skillgroup->getSkillGroupType()== $_POST['grouptype']){
		    			$skillMatrix[0] = $skillgroup;
	    			}else{
	    				$skillMatrix[0] = array();
	    			}	
	    		}else{
	    			$skillMatrix = SkillGroup::getSkillGroupByType($_POST['grouptype']);
	    		}    			
    		}elseif(isset($_POST['skillgroup']) && $_POST['skillgroup']!=''){
	    		$skillgroup = SkillGroup::getSkillGroup($_POST['skillgroup']);
	    		$skillMatrix[0] = $skillgroup;
	    		
	    	}else{
	    		$skillMatrix = SkillGroup::getAll();	
	    	}
			$groupSkills = $skillMatrix;		
			
			if(count($groupSkills)>0){
				$rowtmp= $rowstart;
				
				foreach($groupSkills as $groupSkill){
					$rowstart=$rowtmp;
					$coltmp = $colstart;					
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$groupSkill->getSkillGroupName());
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
					//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
					$rowstart++;
					
					$skillExpertises = SkillGroup::getSkillExpertise($groupSkill->getId());
					if(count($skillExpertises)>0){
						foreach($skillExpertises as $skillExpertise){
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillExpertise->getSkillExpertiseName());	
							if(isset($_POST['lastupdate']))
								$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($colstart)->setWidth(15);	
							$colstart++;
						}
						$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($coltmp,$rowtmp,$coltmp+count($skillExpertises)-1,$rowtmp);
					}
										
				}
			}
			$colstart = 1;
			$rowstart++;
			$empList = SkillIndividual::getEmpSkillInfo($_POST['expertises']);
			if(count($empList)>0){
				$count =1;
				foreach($empList as $emp){
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart-1,$rowstart,$count);
					$count++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$emp[0]." ".$emp[2]." ".$emp[1]);
					if(count($groupSkills)>0){								
						foreach($groupSkills as $groupSkill){
							$skillExpertises = SkillGroup::getSkillExpertise($groupSkill->getId());
							if(count($skillExpertises)>0){
								foreach($skillExpertises as $skillExpertise){
									$colstart++;
									$userSkills = $skillExpertise->getUserSkills($skillExpertise->getId(),$emp[3]);
									if(count($userSkills)>0){
										$value = $userSkills[0]->getSkillUserValue();
										if($userSkills[0]->getSkillUserDateSubmit()!= '0000-00-00 00:00:00' && isset($_POST['lastupdate']))
											$value .= "\n(LU:".date('M d,y',strtotime($userSkills[0]->getSkillUserDateSubmit())).")" ;										
										$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$value);											
										$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
										$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
										
									}
								}
							}
												
						}
					}
					$colstart = 1;
					$rowstart++;					
				}
			}
			
			$rowstart++;
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Total");
				$rowstart++;
			//$objPHPExcel->getAuuctiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Introductory");
				$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Basic");
				$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Intermediate");
				$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Advanced");
				$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Expert");
				$rowstart++;			

			$colstart = 2;
			if(count($empList)>1){	
				$totalRstart = $rowstart-6;
				$totalCstart = $colstart;			
				for($m=0;$m<count($groupSkills);$m++) {
					$record = $groupSkills[$m];
					$skillExpertises = $record->getSkillExpertise($record->getId());
					if(count($skillExpertises)>0){
						
						for($n=0;$n<count($skillExpertises);$n++) {
							$skillExpertise = $skillExpertises[$n];						
							/*$introductory = SkillUser::getIntroductory($skillExpertise->getId());															
							$basic = SkillUser::getBasic($skillExpertise->getId());	
							$intermediate =SkillUser::getIntermediate($skillExpertise->getId());	
							$advanced =    SkillUser::getAdvanced($skillExpertise->getId());
							$expertise = SkillUser::getExpertise($skillExpertise->getId());*/
							
							$totalSum = SkillUser::getTotalSumaryByExpertise($skillExpertise->getId());							
							$introductory = $totalSum[0];																		
							$basic = $totalSum[1]; 	
							$intermediate =$totalSum[2];
							$advanced = $totalSum[3];	
							$expertise = $totalSum[4];
							//$total = $basic+$intermediate+$expertise;
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart-5,$introductory);
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart-4,$basic);
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart-3,$intermediate);														
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart-2,$advanced);
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart-1,$expertise);			
							$colstart++;
						}
						
					}
				}
				$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($totalCstart,$totalRstart,$colstart-1,$totalRstart);
			}
			$colstart=1;
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Legend");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"1: Introductory: Demonstrates introductory understanding and ability and, with guidance, applies the skill in a few simple situations");
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"2: Basic: Demonstrates basic knowledge and ability and, with guidance, can apply the skill in common situations that present limited difficulties");
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"3: Intermediate: Demonstrates solid knowledge and ability, and can apply the skill with minimal or no guidance in the full range of typical situations. Would require guidance to handle novel or more complex situations");
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"4: Advanced: Demonstrates advanced knowledge and ability, and can apply the skill in new or complex situations. Guides other professionals");
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"5: Expert: Demonstrates expert knowledge and ability, and can apply the skill in the most complex situations. Develops new approaches, methods or policies in the area. Is recognized as an expert, internally and/or externally. Leads the guidance of other professionals");
			$rowstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"LU: Last update");
			
			ob_end_clean();
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="'.date('Y-m-d').'_SkillMatrix.xls"');
			header('Cache-Control: max-age=0');
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); 
	  	}
	  	
		/*
		 private function _export(){
		 	
		 	
		 	date_default_timezone_set('Europe/London');

			require_once '../Classes/PHPExcel.php';
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			// Set properties
			$objPHPExcel->getProperties()->setCreator("Skill Matrix module")
										 ->setLastModifiedBy("Chinh Nguyen")
										 ->setTitle("Skill Matrix")
										 ->setSubject("Skill Matrix")
										 ->setDescription("Skill Matrix")
										 ->setKeywords("Skill Matrix")
										 ->setCategory("Skill Matrix");
			$objPHPExcel->setActiveSheetIndex(0);
			// Rename sheet
			$objPHPExcel->getActiveSheet()->setTitle('Staff technical Summary');
			$objPHPExcel->getActiveSheet()->freezePane('C5');
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			
			
			$objPHPExcel->getActiveSheet()->mergeCells('B1:C2');
			$objPHPExcel->getActiveSheet()->setCellValue('B1',"STAFF TECHNICAL SUMMARY");			
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->getColor()->applyFromArray( array('rgb' => 'FF0000'));
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(14);
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			
			$objPHPExcel->getActiveSheet()->mergeCells('B3:C3');
			$date = date("Y-M-d"); 
			$objPHPExcel->getActiveSheet()->setCellValue('B3',"Last update: ".$date);
			
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
			$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
			// Add some data
			$empList = EmpInfo::getEmpSkillInfo();
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1,4,"Employee Name" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(1,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2,4,"Position" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(2,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3,4,"# Year of experience" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(3,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4,4,"Foreign language" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(4,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5,4,"Foreign language Level" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(5,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6,4,"Work abroad" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(6,4)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7,4,"Expertise" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(7,4)->getFont()->setBold(true);
			$rowstart = 5;
			$colstart = 1;
			$lanlist = LanguageInfo::getLang();
			$grdcodes = array("Poor"=> 1 ,"Average"=>2 , "Good"=>3 ,"Excellent"=>4);
			$name=array_keys($grdcodes);
			$code=array_values($grdcodes);
			foreach($empList as $employee){
				$emplan = EmpLanguage::getAssEmpLang($employee[0]);				
				if(!count($emplan)>0){
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[1]." ".$employee[4]." ".$employee[3] );
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
					$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
					//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
					$colstart++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[7]);
					$colstart++;
					
					$skillIndividual = SkillIndividual::getSkillIndividualByUser($employee[0]);
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualNumOfYear());
					$colstart++;
					$colstart++;
					//$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,null);
					$colstart++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualWorkAbroad());
					$colstart++;
					$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualExpertise());
					
					$colstart=1;
					$rowstart++;
				}else{
					for($i=0;$i<count($emplan);$i++){
						if($i==0){	
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[1]." ".$employee[4]." ".$employee[3] );
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
							//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
							$colstart++;
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[7]);
							$colstart++;
							
							$skillIndividual = SkillIndividual::getSkillIndividualByUser($employee[0]);
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualNumOfYear());
							$colstart++;
							$lname='';
							for($a=0;count($lanlist)>$a;$a++)								
								if($emplan[$i][1] == $lanlist[$a][0])
								   $lname=$lanlist[$a][1];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$lname);
							$colstart++;
							$rate='';
							
							for($b=0;count($grdcodes)>$b;$b++)
								if($emplan[$i][3] == $code[$b])
								   $rate=$name[$b];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$rate);
							$colstart++;
							
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualWorkAbroad());
							$colstart++;
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillIndividual->getSkillIndividualExpertise());
							
							$colstart=1;
							$rowstart++;
						}else{
							//Merge here
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);										
							$colstart++;
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);							
							$colstart++;							
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$colstart++;
							$lname='';
							for($a=0;count($lanlist)>$a;$a++)
								if($emplan[$i][1] == $lanlist[$a][0])
								   $lname=$lanlist[$a][1];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$lname);
							$colstart++;
							$rate='';
							$name=array_keys($grdcodes);
							for($b=0;count($grdcodes)>$b;$b++)
								if($emplan[$i][3] == $code[$b])
								   $rate=$name[$b];
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$rate);
							$colstart++;
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							$colstart++;
							$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($colstart,$rowstart-1,$colstart,$rowstart);
							$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart-1)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							
							$colstart=1;
							$rowstart++;
						}
					}
					
				}
			}

			$objPHPExcel->createSheet(1);
			$objPHPExcel->setActiveSheetIndex(1);
			$objPHPExcel->getActiveSheet()->setTitle('Skill Matrix');
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(1);
			
			$objPHPExcel->getActiveSheet()->mergeCells('B2:C3');
			$objPHPExcel->getActiveSheet()->setCellValue('B2',"S3 Skill Matrix");
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => 'FF0000'));
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setSize(14);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			// Add some data
			$empList = EmpInfo::getEmpSkillInfo();
			$rowstart = 5;
			$colstart = 1;
			//$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setAutoSize(true);
		
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Group name");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
			
			$colstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"SkillExpertise");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
			$objPHPExcel->getActiveSheet()->freezePane('D6');
			$colstart++;
			$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(25);
			foreach($empList as $employee){
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[1]." ".$employee[4]." ".$employee[3] );
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
				$colstart++;
			}
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Total" );
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);			
			

			 if(isset($_POST['grouptype']) && $_POST['grouptype']!=''){    		
    			if(isset($_POST['skillgroup']) && $_POST['skillgroup']!='' ){    			
    				$skillgroup = SkillGroup::getSkillGroup($_POST['skillgroup']);
	    			if($skillgroup->getSkillGroupType()== $_POST['grouptype']){
		    			$skillMatrix[0] = $skillgroup;
	    			}else{
	    				$skillMatrix[0] = array();
	    			}	
	    		}else{
	    			$skillMatrix = SkillGroup::getSkillGroupByType($_POST['grouptype']);
	    		}    			
    		}elseif(isset($_POST['skillgroup']) && $_POST['skillgroup']!=''){
	    		$skillgroup = SkillGroup::getSkillGroup($_POST['skillgroup']);
	    		$skillMatrix[0] = $skillgroup;
	    		
	    	}else{
	    		$skillMatrix = SkillGroup::getAll();	
	    	}
			$groupSkills = $skillMatrix;
			$skillset = array("None","Basic","Intermadiate","Expert");			
			if(count($groupSkills) > 0)
			{	$rowstart = 6;
				$colstart = 1;
				foreach($groupSkills as $groupSkill){					
				$skillExpertises = SkillGroup::getSkillExpertise($groupSkill->getId());
				$firstskill = true;				
				foreach($skillExpertises as $skillExpertise){
					if($firstskill){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$groupSkill->getSkillGroupName());
						$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
						$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						$colstart++;
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillExpertise->getSkillExpertiseName());
						$colstart++;
						$total=0;
						$basic=0;
    					$intermediate=0;
    					$expertise=0;  
						foreach($empList as $employee){
							$userSkills = SkillExpertise::getUserSkills($skillExpertise->getId(),$employee[0]);							
							if(count($userSkills)>0){
								$level=$userSkills[0]->getSkillUserValue();
					        	$value = '';
					        	$total++;
					        	if($level<4){
					        		$value .=  $skillset[$level];
					        		if($level==1)
			        					$basic++;
			        				elseif($level==1)
			        					$intermediate++;
			        				else
			        					$expertise++;
								
								if($userSkills[0]->getSkillUserDateSubmit()!= '0000-00-00 00:00:00' && isset($_POST['lastupdate']))
									$value .= "(".date('M d,y',strtotime($userSkills[0]->getSkillUserDateSubmit())).")" ;
								}
							}
							else{
									$value = null;
							}
							$objPHPExcel->getActiveSheet()->getStyle($colstart,$rowstart)->getAlignment()->setWrapText(true);	
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$value);
							$colstart++;	
						}
						$objPHPExcel->getActiveSheet()->getStyle($colstart,$rowstart)->getAlignment()->setWrapText(true);
						$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($colstart)->setWidth(35);	
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$total."(Basic: $basic, Intermediate: $intermediate, Expert: $expertise)");
						
						$colstart = 1;				
						$rowstart++;
						$firstskill=false;
					}else{
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,null);
						$colstart++;
						$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);	
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillExpertise->getSkillExpertiseName());
						$colstart++;
						$total=0;
						$basic=0;
    					$intermediate=0;
    					$expertise=0;
						foreach($empList as $employee){
							$userSkills = SkillExpertise::getUserSkills($skillExpertise->getId(),$employee[0]);
							
						if(count($userSkills)>0){
								$level=$userSkills[0]->getSkillUserValue();
					        	$value = '';
					        	if($level<4){
					        		$value .=  $skillset[$level];
					        		$total++;
					        		if($level==1)
			        					$basic++;
			        				elseif($level==1)
			        					$intermediate++;
			        				else
			        					$expertise++;
								
								if($userSkills[0]->getSkillUserDateSubmit()!= '0000-00-00 00:00:00' && isset($_POST['lastupdate']))
									$value .= "(".date('M d,y',strtotime($userSkills[0]->getSkillUserDateSubmit())).")" ;
								}
							}
							else{
									$value = null;
							}	
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$value);
							$colstart++;	
						}
						$objPHPExcel->getActiveSheet()->getStyle($colstart,$rowstart)->getAlignment()->setWrapText(true);
						$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($colstart)->setWidth(35);	
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$total."(Basic: $basic, Intermediate: $intermediate, Expert: $expertise)");
						$colstart = 1;				
						$rowstart++;						
					}
					
				}
				$mergend = $rowstart;
				$merge = "B".($mergend - count($skillExpertises)).":B".($mergend-1);
				//die($merge);
				$objPHPExcel->getActiveSheet()->mergeCells($merge);
				
				}			
			}
			ob_end_clean();
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="'.date('Y-m-d').'_SkillMatrix.xls"');
			header('Cache-Control: max-age=0');
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); 
	  	} 
		 private function _export(){
		 	
		 	
		 	date_default_timezone_set('Europe/London');

			require_once '../Classes/PHPExcel.php';
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			// Set properties
			$objPHPExcel->getProperties()->setCreator("Skill Matrix module")
										 ->setLastModifiedBy("Chinh Nguyen")
										 ->setTitle("Skill Matrix")
										 ->setSubject("Skill Matrix")
										 ->setDescription("Skill Matrix")
										 ->setKeywords("Skill Matrix")
										 ->setCategory("Skill Matrix");
			// Rename sheet
			$objPHPExcel->getActiveSheet()->setTitle('Skill Matrix');
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			
			$objPHPExcel->getActiveSheet()->mergeCells('B2:C3');
			$objPHPExcel->getActiveSheet()->setCellValue('B2',"S3 Skill Matrix");
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => 'FF0000'));
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setSize(14);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			// Add some data
			$empList = EmpInfo::getEmpSkillInfo();
			$rowstart = 5;
			$colstart = 1;
			//$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setAutoSize(true);
		
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"Group name");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
			$colstart++;
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,"SkillExpertise");
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
			$objPHPExcel->getActiveSheet()->freezePane('D6');
			$colstart++;
			foreach($empList as $employee){
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$employee[1]." ".$employee[4]." ".$employee[3] );
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getFont()->setBold(true);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				//$objPHPExcel->getActiveSheet()->getColumnDimension($colstart)->setAutoSize(true);
				$colstart++;
			}			
			

			 if(isset($_POST['grouptype']) && $_POST['grouptype']!=''){    		
    			if(isset($_POST['skillgroup']) && $_POST['skillgroup']!='' ){    			
    				$skillgroup = SkillGroup::getSkillGroup($_POST['skillgroup']);
	    			if($skillgroup->getSkillGroupType()== $_POST['grouptype']){
		    			$skillMatrix[0] = $skillgroup;
	    			}else{
	    				$skillMatrix[0] = array();
	    			}	
	    		}else{
	    			$skillMatrix = SkillGroup::getSkillGroupByType($_POST['grouptype']);
	    		}    			
    		}elseif(isset($_POST['skillgroup']) && $_POST['skillgroup']!=''){
	    		$skillgroup = SkillGroup::getSkillGroup($_POST['skillgroup']);
	    		$skillMatrix[0] = $skillgroup;
	    		
	    	}else{
	    		$skillMatrix = SkillGroup::getAll();	
	    	}
			$groupSkills = $skillMatrix;			
			if(count($groupSkills) > 0)
			{	$rowstart = 6;
				$colstart = 1;
				foreach($groupSkills as $groupSkill){					
				$skillExpertises = SkillGroup::getSkillExpertise($groupSkill->getId());
				$firstskill = true;				
				foreach($skillExpertises as $skillExpertise){
					if($firstskill){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$groupSkill->getSkillGroupName());
						$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
						$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						$colstart++;
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillExpertise->getSkillExpertiseName());
						$colstart++;
						foreach($empList as $employee){
							$userSkills = SkillExpertise::getUserSkills($skillExpertise->getId(),$employee[0]);							
							if(count($userSkills)>0){
									$value = $userSkills[0]->getSkillUserValue();								
							}
							else{
									$value = null;
							}
							$objPHPExcel->getActiveSheet()->getStyle($colstart,$rowstart)->getAlignment()->setWrapText(true);	
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$value);
							$colstart++;	
						}
						$colstart = 1;				
						$rowstart++;
						$firstskill=false;
					}else{
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,null);
						$colstart++;
						$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($colstart,$rowstart)->getAlignment()->setWrapText(true);	
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$skillExpertise->getSkillExpertiseName());
						$colstart++;
						foreach($empList as $employee){
							$userSkills = SkillExpertise::getUserSkills($skillExpertise->getId(),$employee[0]);
							
							if(count($userSkills)>0){
									$value = $userSkills[0]->getSkillUserValue();
								
							}
							else{
									$value = null;
							}	
							$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($colstart,$rowstart,$value);
							$colstart++;	
						}
						$colstart = 1;				
						$rowstart++;						
					}
					
				}
				$mergend = $rowstart;
				$merge = "B".($mergend - count($skillExpertises)).":B".($mergend-1);
				//die($merge);
				$objPHPExcel->getActiveSheet()->mergeCells($merge);
				
				}			
			}
												 
			
			ob_end_clean();
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="'.date('Y-m-d').'_SkillMatrix.xls"');
			header('Cache-Control: max-age=0');
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output'); 
	  	}
*/
		
	 
	
	 private function _exportCSV(){
	 	$skillExport = new SkillMatrixCSVExport();
	 	
	 	$fileName = "skill matrix export";
		//$csvContents = $skillExport->getHeader() . "\n" . $skillExport->getCSVData();
		$csvContents=$csvContents = "Group name,SkillExpertise";
		$empList = EmpInfo::getEmpSkillInfo();
		foreach($empList as $employee){
			$csvContents = $csvContents.",".$employee[1]." ".$employee[4]." ".$employee[3] ;
		}
		$csvContents .= ", Total". "\n" ;//. $skillExport->getCSVData();
		$groupSkills = SkillGroup::getAll();
		$firstField = true;
		foreach($groupSkills as $groupSkill){
			$skillExpertises = SkillGroup::getSkillExpertise($groupSkill->getId());
			$firstskill = true;
			foreach($skillExpertises as $skillExpertise){				
					if($firstskill){
						$csvContents .=  $groupSkill->getSkillGroupName().",".$skillExpertise->getSkillExpertiseName();
						$total =0;
						for($i=0;$i<count($empList);$i++){
							$userSkills = SkillExpertise::getUserSkills($skillExpertise->getId(),$empList[$i][0]);
							if(count($userSkills)>0){
								$csvContents .= ",".$userSkills[0]->getSkillUserValue();
								$total ++;
							}
							else{
								$csvContents .= ",".'';
							}								 											
						}
						$csvContents .= ",".$total;
						$csvContents .= "\n";
						$firstskill =false;
					}else{
						$csvContents .=  ''.",".$skillExpertise->getSkillExpertiseName();
						$total =0;
						for($i=0;$i<count($empList);$i++){
							$userSkills = SkillExpertise::getUserSkills($skillExpertise->getId(),$empList[$i][0]);
							if(count($userSkills)>0){
								$csvContents .= ",".$userSkills[0]->getSkillUserValue();
								$total ++;
							}
							else{
								$csvContents .= ",".'';
							}											
						}
						$csvContents .= ",".$total;
						$csvContents .= "\n";
					}
				//$userSkills = SkillExpertise::ge
			}
			$firstField=true;
		}
		ob_end_clean();
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: private", false);
		header("Content-Type: text/csv");
		header('Content-Disposition: attachment; filename="' . $fileName . '.csv";');
		header("Content-Transfer-Encoding: none");
		//header("Content-Length: " .strlen($csvContents));
		echo $csvContents;
	 }
	
	

	/**
	 * Redirect to given url or current page while displaying optional message
	 *
	 * @param String $message Message to display
	 * @param String $url URL
	 */
	public function redirect($message=null, $url = null) {

		if (isset($url)) {
			$mes = "";
			if (isset($message)) {
				$mes = "&message=";
			}
			$url=array($url.$mes);
			$id="";
		} else if (isset($message)) {
			preg_replace('/[&|?]+id=[A-Za-z0-9]*/', "", $_SERVER['HTTP_REFERER']);

			if (preg_match('/&/', $_SERVER['HTTP_REFERER']) > 0) {
				$message = "&message=".$message;
				$url = preg_split('/(&||\?)message=[A-Za-z0-9]*/', $_SERVER['HTTP_REFERER']);
			} else {
				$message = "?message=".$message;
			}

			if (isset($_REQUEST['id']) && !empty($_REQUEST['id']) && !is_array($_REQUEST['id'])) {
				$id = "&id=".$_REQUEST['id'];
			} else {
				$id="";
			}
		} else {
			if (isset($_REQUEST['id']) && !empty($_REQUEST['id']) && (preg_match('/&/', $_SERVER['HTTP_REFERER']) > 0)) {
				$id = "&id=".$_REQUEST['id'];
			} else if (preg_match('/&/', $_SERVER['HTTP_REFERER']) == 0){
				$id = "?id=".$_REQUEST['id'];
			} else {
				$id="";
			}
		}

		header("Location: ".$url[0].$message.$id);
	}

    /**
     * Show not authorized message
     */
    private function _notAuthorized() {
        trigger_error("Not Authorized!", E_USER_NOTICE);
    }
}
?>